package org.easy.core.enums;

import lombok.Getter;
import lombok.ToString;

@Getter
@ToString
public enum GenderType {
    MALE(0, "男"),
    FEMALE(1, "女"),
    UNKNOWN(2, "保密");

    private int code;
    private String description;

    GenderType(int code, String description) {
        this.code = code;
        this.description = description;
    }

    public int getCode() {
        return code;
    }

    public String getDescription() {
        return description;
    }

    // 根据代码获取枚举
    public static GenderType fromCode(Integer code) {
        if (code == null) {
            return GenderType.UNKNOWN;
        }
        for (GenderType gender : values()) {
            if (gender.getCode() == code) {
                return gender;
            }
        }
        throw new IllegalArgumentException("未知的性别代码: " + code);
    }

}
